﻿Ext.define('Html5App.controller.InformationController', {
	extend : 'Ext.app.Controller',
	config : {
		models : [],
		views : [],
		refs : {
			informationDataList : 'informationDataList',
			informationVideo : 'informationVideo',
			openFileAction : 'button[action=openFileAction]'
		},
		control : {
			informationDataList : {
				activate : function(newActiveItem, t, oldActiveItem, eOpts) {
					config.database.transaction(
						function (tx) {
			                tx.executeSql("select * from LocalFile where filetype = '"+config.file_type+"'",
			                	[],
			                	function (tx, r) {
			                		if(Number(r.rows.length) > 0){
			                			for (var i = 0; i < r.rows.length; i++) {
			                				Ext.getCmp('information_data_list').add(
												{
													xtype : 'button',
													cls : 'information-data-button',
													html : ''+r.rows.item(i)['filename'],
													data : ''+r.rows.item(i)['filepath'],
													action : 'openFileAction'
												}
											);
			                				Ext.getCmp('information_data_list').add(
												{
													cls : 'customer-options-panel-line'
												}
											);
			                			}
			                		}else{
			                			util.showMessageMask('無資訊文件','warn-max');
			                		}
			                	},
			                	function (tx, error) {}
			                );
						}
					);
				}
			},
			openFileAction : {
				tap : function(button, e, eOpts) {
					window.openFile.getOpenFile(null,function () {
						util.showMessageMask('請安裝該文件格式的查看應用程序','warn-max');
					},[button.getData()]);
				}
			}
		}
	}
});